package org.blogwu.learn.multithread.chapter2.demo3;

public class Test4 {

    final static Object obj = new Object();

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (obj) {
                    try {
                        Thread.sleep(2000);
                        obj.wait();
                        System.out.println("t1 继续执行");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                    synchronized (obj) {
                        System.out.println("t2 获取到锁了");
                        obj.notify();
                        System.out.println("t2 执行完毕");
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }


            }
        });

        t1.start();
        t2.start();
        t1.join();
        t2.join();
    }
}
